﻿using System;
using System.Text;

namespace CSharp进阶_泛型编程
{
	interface IFly<T>
	{
		void Fly();
		T Value { get; set; }
		T this[int pos] { get; set; }
		//event EventHandler OnFly;
	}
	class Bird : IFly<int>
	{
		public void Fly() { }
		public int Value { get; set; }
		public int this[int pos]
		{
			get
			{
				return 0;
			}

			set
			{
				Value = value;
			}
		}

	}
	class Bird<T> : IFly<int>
	{
		public int this[int pos] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

		public int Value { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

		public void Fly()
		{
			throw new NotImplementedException();
		}
	}
	class Test<T>
	{
		public T data_;
		public Test(T data = default(T))
		{
			data_ = data;
		}

		public K Print<K>() {
			K value = default(K);
			return value;
		}
	}
	
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine(IsType('a'));
			Console.WriteLine(IsType(1));
			Console.WriteLine(IsType(1.1f));
			Console.WriteLine(IsType("111asddddddddddd1"));
			Console.WriteLine(IsType(new Test<int>()));
			//Add(1, 2);
			//Add(1, 2.1f);
			//Add(1.1f, 2);
			//Add(1.1f, 2.1f);
			//Add<float, float>(1.1f, 2.1f);
			//Test<int> t1 = new Test<int>(100);
		}
		static string IsType<T>(T val)
		{
			if (typeof(T) == typeof(char))
			{
				return string.Format("字符，{0}字节", sizeof(char));
			}
			else if (typeof(T) == typeof(int))
			{
				return string.Format("整型，{0}字节", sizeof(int));
			}
			else if (typeof(T) == typeof(float))
			{
				return string.Format("单精度浮点型，{0}字节", sizeof(float));
			}
			else if (typeof(T) == typeof(string))
			{
				string str = val.ToString();
				return string.Format(string.Format("字符串，{0}字节", str.Length));
			}
			else
			{
				return string.Format("其他类型");
			}
		}

		//static void Add(int a, int b)
		//{
		//	Console.WriteLine("static void Add(int a, int b)");
		//}

		//static void Add(float a, float b)
		//{
		//	Console.WriteLine("static void Add(float a, float b)");
		//}
		//static void Add(int a, float b)
		//{
		//	Console.WriteLine("static void Add(int a, float b)");
		//}
		//static void Add(float a, int b)
		//{
		//	Console.WriteLine("static void Add(float a, int b)");
		//}

		//static void Add<T1, T2>(T1 a, T2 b)
		//{
		//	Console.WriteLine("static void Add<T1, T2>(T1 a, T2 b)");

		//}
	}
}
